package com.hippo.core.ui.compose.home.add

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hippo.core.R
import com.hippo.core.ui.components.BottomSheetDialog
import com.hippo.core.ui.components.SecondaryButton
import com.hippo.core.ui.components.ThemeButton
import com.hippo.core.ui.theme.ColorTextBlack
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun ConfirmWifiDialog(
    ssid:String,
    pwd:String,
    onDismissRequest: () -> Unit,
    onConfirm: (String,String) -> Unit,
    onReenter: () -> Unit
) {

    BottomSheetDialog(
        title = stringResource(R.string.home_17),
        onDismissRequest = onDismissRequest,
        skipPartiallyExpanded = true,
    ) {
        ConfirmWifiContent(
            ssid = ssid,
            pwd = pwd,
            onDismissRequest = onDismissRequest,
            onConfirm = onConfirm,
            onReenter = onReenter
        )
    }



}


@Composable
fun ConfirmWifiContent(
    ssid:String,
    pwd:String,
    onDismissRequest: () -> Unit,
    onConfirm: (String,String) -> Unit,
    onReenter: () -> Unit
) {
    Column(modifier = Modifier.padding(16.dp)) {

        Spacer(modifier = Modifier.height(26.dp))

        Row(
            verticalAlignment = Alignment.CenterVertically
        ) {
            Image(
                painter = painterResource(R.mipmap.wifi_n),
                contentDescription = null,
                modifier = Modifier.size(25.dp)
            )
            Text(
                text = ssid,
                modifier = Modifier.padding(start = 16.dp),
                style = TextStyle(
                    color = ColorTextBlack,
                    fontSize = 14.sp
                )
            )
        }

        Spacer(modifier = Modifier.height(26.dp))

        Row(
            verticalAlignment = Alignment.CenterVertically
        ) {
            Image(
                painter = painterResource(R.mipmap.pwd_2),
                contentDescription = null,
                modifier = Modifier.size(25.dp)
            )
            Text(
                text = pwd,
                modifier = Modifier.padding(start = 16.dp),
                style = TextStyle(
                    color = ColorTextBlack,
                    fontSize = 14.sp
                )
            )
        }

        Spacer(modifier = Modifier.height(56.dp))

        ThemeButton(
            text = stringResource(R.string.home_18),
            onClick = {
                onConfirm(ssid,pwd)
            }
        )

        Spacer(modifier = Modifier.height(16.dp))

        SecondaryButton(
            text = stringResource(R.string.home_19),
            onClick = {
                onDismissRequest()
                onReenter()
            }
        )
    }
}


@Preview(showBackground = true)
@Composable
private fun ConfirmWifiDialogPreview() {
    HippoTheme {
        ConfirmWifiContent(
            ssid = "ssid",
            pwd = "123456",
            onDismissRequest = {},
            onConfirm = {_,_ ->},
            onReenter = {}
        )
    }
}
